package com.fhzn.auth.web.converter;

import com.fhzn.auth.entity.DataResource;
import com.fhzn.auth.tools.DateTimeUtils;
import com.fhzn.auth.web.vo.DataResourceVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 老顾
 * @apiNote
 * @since 2024/1/18
 */
public interface DataResourceConverter {

    /**
     * 实体列表转VO列表
     *
     * @param resources 资源列表
     * @return 资源VO列表
     */
    static List<DataResourceVO> convertToVoList(List<DataResource> resources) {
        return resources.stream().map(DataResourceConverter::fromDataResource).collect(Collectors.toList());
    }

    /**
     * 实体转VO
     *
     * @param dataResource 资源实体
     * @return 资源VO
     */
    static DataResourceVO fromDataResource(DataResource dataResource) {
        DataResourceVO vo = new DataResourceVO();
        if (dataResource != null) {
            vo.setAppCode(dataResource.getAppCode());
            vo.setCode(dataResource.getCode());
            vo.setName(dataResource.getName());
            vo.setParentCode(dataResource.getParentCode());
            vo.setComment(dataResource.getComment());
            vo.setResourceType(dataResource.getResourceType());
            vo.setStatus(dataResource.getStatus());
            vo.setSort(dataResource.getSort());
            vo.setCreatedTime(DateTimeUtils.format(dataResource.getCreatedTime()));
            vo.setUpdatedTime(DateTimeUtils.format(dataResource.getUpdatedTime()));
            vo.setCreator(dataResource.getCreator());
        }
        return vo;
    }
}
